<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
  File: HowToContribute
  
    &mdash; FSelector Documentation
  
</title>

  <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />

  <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  relpath = '';
  if (relpath != '') relpath += '/';
</script>

  <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="js/app.js"></script>


  </head>
  <body>
    <script type="text/javascript" charset="utf-8">
      if (window.top.frames.main) document.body.className = 'frames';
    </script>
    
    <div id="header">
      <div id="menu">
  
    <a href="_index.html" title="Index">Index</a> &raquo; 
    <span class="title">File: HowToContribute</span>
  
  
  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a id="class_list_link" href="#">Class List</a>
  
    <a id="method_list_link" href="#">Method List</a>
  
    <a id="file_list_link" href="#">File List</a>
  
</div>
      <div class="clear"></div>
    </div>
    
    <iframe id="search_frame"></iframe>
    
    <div id="content"><div id='filecontents'><h2>How to add your own feature selection algorithms</h2>

<p><strong>Baisc steps</strong></p>

<pre class="code ruby"><code>1. Require the FSelector gem

2. Derive a subclass from a base class (Base, BaseDiscrete, BaseContinuous and etc.)  

3. Set your own feature selection algorithm with one of the following two types:  
  :feature_weighting         # if it outputs weight for each feature
  :feature_subset_selection  # if it outputs a subset of original feature set

4. Depending on your algorithm type, override one of the following two interfaces:
  calc_contribution()   # if it belongs to the type of feature weighting algorithms
  get_feature_subset()  # if it belongs to the type of feature subset selection algorithms
</code></pre>

<p><strong>Example</strong></p>

<pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>fselector</span><span class='tstring_end'>'</span></span>  <span class='comment'># step 1
</span>
<span class='kw'>module</span> <span class='const'>FSelector</span>
  <span class='comment'># create a new algorithm belonging to the type of feature weighting
</span>  <span class='comment'># to this end, simply override the calc_contribution() in Base class
</span>  <span class='kw'>class</span> <span class='const'>NewAlgo_Weight</span> <span class='op'>&lt;</span> <span class='const'>Base</span>  <span class='comment'># step 2
</span>    <span class='comment'># set the algorithm type
</span>    <span class='ivar'>@algo_type</span> <span class='op'>=</span> <span class='symbol'>:feature_weighting</span>  <span class='comment'># step 3
</span>
    <span class='comment'># add your own initialize() here if necessary
</span>
    <span class='id identifier rubyid_private'>private</span>

    <span class='comment'># the algorithm assigns feature weight randomly
</span>    <span class='kw'>def</span> <span class='id identifier rubyid_calc_contribution'>calc_contribution</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='rparen'>)</span>  <span class='comment'># step 4
</span>      <span class='id identifier rubyid_s'>s</span> <span class='op'>=</span> <span class='id identifier rubyid_rand'>rand</span>

      <span class='comment'># set the score (s) of feature (f) for class (:BEST is the best score among all classes)
</span>      <span class='id identifier rubyid_set_feature_score'>set_feature_score</span><span class='lparen'>(</span><span class='id identifier rubyid_f'>f</span><span class='comma'>,</span> <span class='symbol'>:BEST</span><span class='comma'>,</span> <span class='id identifier rubyid_s'>s</span><span class='rparen'>)</span>
    <span class='kw'>end</span>
  <span class='kw'>end</span> <span class='comment'># NewAlgo_Weight
</span>

  <span class='comment'># create a new algorithm belonging to the type of feature subset selection
</span>  <span class='comment'># to this end, simly override the get_feature_subset() in Base class
</span>  <span class='kw'>class</span> <span class='const'>NewAlgo_Subset</span> <span class='op'>&lt;</span> <span class='const'>Base</span>  <span class='comment'># step 2
</span>    <span class='comment'># set the algorithm type
</span>    <span class='ivar'>@algo_type</span> <span class='op'>=</span> <span class='symbol'>:feature_subset_selection</span>  <span class='comment'># step 3
</span>
    <span class='comment'># add your own initialize() here if necessary
</span>
    <span class='id identifier rubyid_private'>private</span>

    <span class='comment'># the algorithm returns a random half-size subset of the orignal one
</span>    <span class='kw'>def</span> <span class='id identifier rubyid_get_feature_subset'>get_feature_subset</span>  <span class='comment'># step 4
</span>      <span class='id identifier rubyid_org_features'>org_features</span> <span class='op'>=</span> <span class='id identifier rubyid_get_features'>get_features</span>
      <span class='id identifier rubyid_subset'>subset</span> <span class='op'>=</span> <span class='id identifier rubyid_org_features'>org_features</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span><span class='lparen'>(</span><span class='id identifier rubyid_org_features'>org_features</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span><span class='op'>/</span><span class='int'>2</span><span class='rparen'>)</span>

      <span class='id identifier rubyid_subset'>subset</span>
    <span class='kw'>end</span>

  <span class='kw'>end</span> <span class='comment'># NewAlgo_Subset
</span><span class='kw'>end</span> <span class='comment'># module
</span></code></pre>

<p><strong>Test your algorithms</strong></p>

<pre class="code ruby"><code><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>fselector</span><span class='tstring_end'>'</span></span>

<span class='comment'># example 1
</span>
<span class='comment'># use NewAlgo_Weighting
</span><span class='id identifier rubyid_r1'>r1</span> <span class='op'>=</span> <span class='const'>FSelector</span><span class='op'>::</span><span class='const'>NewAlgo_Weight</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_data_from_csv'>data_from_csv</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>test/iris.csv</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_select_feature_by_rank!'>select_feature_by_rank!</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>&lt;=1</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_r1'>r1</span><span class='period'>.</span><span class='id identifier rubyid_get_features'>get_features</span>

<span class='comment'># example 2
</span>
<span class='comment'># use NewAlgo_Subset
</span><span class='id identifier rubyid_r2'>r2</span> <span class='op'>=</span> <span class='const'>FSelector</span><span class='op'>::</span><span class='const'>NewAlgo_Subset</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
<span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_data_from_csv'>data_from_csv</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>test/iris.csv</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
<span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_select_feature!'>select_feature!</span>
<span class='id identifier rubyid_puts'>puts</span> <span class='id identifier rubyid_r2'>r2</span><span class='period'>.</span><span class='id identifier rubyid_get_features'>get_features</span>
</code></pre>

<h2>How to become a contributor of FSelector on GitHub</h2>

<p><strong>Set up your repository</strong></p>

<pre class="code ruby"><code>1. Go to https://github.com/need47/fselector and click the &quot;Fork&quot; button

2. Clone your fork to your local machine:
  git clone git@github.com:yourGitUserName/fselector.git

3. Assign the original repository to a remote called &quot;upstream&quot;:  
  cd fselector  
  git remote add upstream git://github.com/need47/fselector.git

4. Get updates from the &quot;upstream&quot; and merge to your local repository:  
  git fetch upstream  
  git merge upstream/master
</code></pre>

<p><strong>Develop features</strong></p>

<pre class="code ruby"><code>1. Create and checkout a feature branch to house your edits:
  git checkout -b branchName

2. Add your own feature selection algorithm:
  git add yourAlgorithm.rb  
  git commit -m &quot;your commit message&quot;

3. Push your branch to GitHub:  
  git push origin branchName

4. Visit your forked project on GitHub and switch to your branhName branch  

5. Click the &quot;Pull Request&quot; button to request that your features to be merged to the &quot;upstream&quot; master
</code></pre>
</div></div>
    
    <div id="footer">
  Generated on Mon Nov  5 11:19:43 2012 by 
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.7.5 (ruby-1.9.3).
</div>

  </body>
</html>